<!-- 企业用户收益信息统计 -->
<template>
  <div>
    <HomeCard
      title="企业用户收益信息统计"
      isDept
      isTimer
      isSearch
      headIcon="img_10"
      @checkedTimer="checkedTimer"
      @checkedSearch="checkedSearch"
    >
      <template v-slot:content>
        <div class="tabs-list">
          <div
            class="tabs-item"
            :class="currentItem == item.id ? 'tabs-item-current' : ''"
            v-for="item in tabsList"
            :key="item.id"
            @click="tabsClick(item)"
          >
            {{ item.name }}
          </div>
        </div>
        <div class="business-info-right">
          <HomeEcharts
            ref="EchartsRef"
            :echartsOption="echartsOption"
            v-if="isHide"
          />
          <div class="loading-main" v-else>
            <Spin></Spin>
          </div>
        </div>
      </template>
    </HomeCard>
  </div>
</template>

<script type="text/javascript">
import HomeCard from "@/pages/components/homeCard/index.vue";
import HomeEcharts from "@/pages/components/homeEcharts/index.vue";

import {
  platformCompanyBusiCountDateStatistics,
  platformCompanyEarningsDateStatistics,
} from "@/api/home";

let labelList = ["信息总数", "企业接收"];

export default {
  name: "todo-page",
  components: {
    HomeCard,
    HomeEcharts,
  },
  data() {
    return {
      visitChart: null,
      echartsOption: {},
      infoOption: {
        backgroundColor: "#fff",
        legend: {
          itemWidth: 20,
          itemHeight: 4,
          // itemGap: 10,
          show: true,
          data: [
            {
              name: "液压异常报警",
            },
            {
              name: "液位异常报警",
            },
          ],
        },
        dataZoom: [
          {
            // 设置滚动条的隐藏与显示
            show: true,
            // 设置滚动条类型
            type: "slider",
            // 设置背景颜色
            // backgroundColor: "#fefefe",
            // // 设置选中范围的填充颜色
            // fillerColor: "#2d8cf0",
            // // 设置边框颜色
            // borderColor: "#2d8cf0",
            // 是否显示detail，即拖拽时候显示详细数值信息
            showDetail: false,
            // 数据窗口范围的起始数值
            startValue: 0,
            // 数据窗口范围的结束数值（一页显示多少条数据）
            endValue: 5,
            // empty：当前数据窗口外的数据，被设置为空。
            // 即不会影响其他轴的数据范围
            filterMode: "empty",
            // 设置滚动条宽度，相对于盒子宽度
            width: "50%",
            // 设置滚动条高度
            height: 8,
            // 设置滚动条显示位置
            left: "center",
            // 是否锁定选择区域（或叫做数据窗口）的大小
            zoomLoxk: true,
            // 控制手柄的尺寸
            handleSize: 0,
            // dataZoom-slider组件离容器下侧的距离
            bottom: 3,
          },
          {
            // 没有下面这块的话，只能拖动滚动条，
            // 鼠标滚轮在区域内不能控制外部滚动条
            type: "inside",
            // 滚轮是否触发缩放
            zoomOnMouseWheel: false,
            // 鼠标滚轮触发滚动
            moveOnMouseMove: true,
            moveOnMouseWheel: true,
          },
        ],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(0, 255, 233,0)",
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255, 255, 255,1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(0, 255, 233,0)",
                  },
                ],
                global: false,
              },
            },
          },
        },
        grid: {
          top: "15%",
          left: "10%",
          right: "5%",
          bottom: "15%",
          // containLabel: true
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false,
              color: "#A582EA",
            },

            axisLabel: {
              color: "#A582EA",
              width: 100,
              margin: 20,
            },
            data: [], //this.$moment(data.times).format("HH-mm") ,
          },
        ],

        yAxis: [
          {
            type: "value",
            min: 0,
            // max: 140,
            splitNumber: 4,
            splitLine: {
              show: true,
              lineStyle: {
                color: "#00BFF3",
                opacity: 0.23,
              },
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              margin: 20,
              textStyle: {
                color: "#333",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "液压异常报警",
            type: "line",
            showAllSymbol: true,
            symbol: "circle",
            symbolSize: 10,
            lineStyle: {
              normal: {
                color: "#A582EA",
              },
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                color: "#A582EA",
              },
            },
            itemStyle: {
              color: "#A582EA",
              borderColor: "#fff",
              borderWidth: 2,
            },

            data: [], //data.values
          },
          {
            name: "液位异常报警",
            type: "line",
            showAllSymbol: true,
            symbol: "circle",
            symbolSize: 10,
            lineStyle: {
              normal: {
                color: "#2CABE3",
              },
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                color: "#2CABE3",
              },
            },
            itemStyle: {
              color: "#2CABE3",
              borderColor: "#fff",
              borderWidth: 2,
            },
            data: [], //data.values
          },
        ],
      },
      amountOption: {
        backgroundColor: "#fff",
        legend: {
          itemWidth: 20,
          itemHeight: 4,
          // itemGap: 10,
          show: true,
          data: [
            {
              name: "金额",
            },
          ],
        },
        dataZoom: [
          {
            // 设置滚动条的隐藏与显示
            show: true,
            // 设置滚动条类型
            type: "slider",
            // 设置背景颜色
            // backgroundColor: "#fefefe",
            // // 设置选中范围的填充颜色
            // fillerColor: "#2d8cf0",
            // // 设置边框颜色
            // borderColor: "#2d8cf0",
            // 是否显示detail，即拖拽时候显示详细数值信息
            showDetail: false,
            // 数据窗口范围的起始数值
            startValue: 0,
            // 数据窗口范围的结束数值（一页显示多少条数据）
            endValue: 5,
            // empty：当前数据窗口外的数据，被设置为空。
            // 即不会影响其他轴的数据范围
            filterMode: "empty",
            // 设置滚动条宽度，相对于盒子宽度
            width: "50%",
            // 设置滚动条高度
            height: 8,
            // 设置滚动条显示位置
            left: "center",
            // 是否锁定选择区域（或叫做数据窗口）的大小
            zoomLoxk: true,
            // 控制手柄的尺寸
            handleSize: 0,
            // dataZoom-slider组件离容器下侧的距离
            bottom: 3,
          },
          {
            // 没有下面这块的话，只能拖动滚动条，
            // 鼠标滚轮在区域内不能控制外部滚动条
            type: "inside",
            // 滚轮是否触发缩放
            zoomOnMouseWheel: false,
            // 鼠标滚轮触发滚动
            moveOnMouseMove: true,
            moveOnMouseWheel: true,
          },
        ],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(0, 255, 233,0)",
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255, 255, 255,1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(0, 255, 233,0)",
                  },
                ],
                global: false,
              },
            },
          },
        },
        grid: {
          top: "15%",
          left: "10%",
          right: "5%",
          bottom: "15%",
          // containLabel: true
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false,
              color: "#A582EA",
            },

            axisLabel: {
              color: "#A582EA",
              width: 100,
              margin: 20,
            },
            data: [], //this.$moment(data.times).format("HH-mm") ,
          },
        ],

        yAxis: [
          {
            type: "value",
            min: 0,
            // max: 140,
            splitNumber: 4,
            splitLine: {
              show: true,
              lineStyle: {
                color: "#00BFF3",
                opacity: 0.23,
              },
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              margin: 20,
              textStyle: {
                color: "#333",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "金额",
            type: "line",
            showAllSymbol: true,
            symbol: "circle",
            symbolSize: 10,
            lineStyle: {
              normal: {
                color: "#A582EA",
              },
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                color: "#A582EA",
              },
            },
            itemStyle: {
              color: "#A582EA",
              borderColor: "#fff",
              borderWidth: 2,
            },

            data: [], //data.values
          },
        ],
      },
      dateType: "Day",
      orgId: "",
      tabsList: [
        {
          id: 1,
          name: "信息数量",
        },
        {
          id: 2,
          name: "金额统计",
        },
      ],
      currentItem: 1,
      isHide: false,
    };
  },
  methods: {
    checkedTimer(item) {
      this.dateType = item;
      this.switchFn();
    },
    checkedSearch(item) {
      this.orgId = item;
      this.switchFn();
    },
    async platformCompanyBusiCountDateStatisticsData() {
      let params = {
        dateType: this.dateType,
        orgId: this.orgId,
      };
      let data = await platformCompanyBusiCountDateStatistics(params);
      let infoTotal = [];
      this.infoOption.legend.data = labelList.map((o) => {
        return {
          name: o,
        };
      });
      this.infoOption.xAxis[0].data = data.publishBusiInfoCountList.map(
        (o) => o.dateStr
      );
      infoTotal[0] = data.publishBusiInfoCountList.map((o) => o.count);
      infoTotal[1] = data.receiveBusiInfoCountList.map((o) => o.count);
      this.infoOption.series.forEach((o, i) => {
        o.name = labelList[i];
        o.data = infoTotal[i];
      });
      this.echartsOption = this.infoOption;
      this.isHide = true;
      this.$nextTick(() => {
        this.$refs.EchartsRef.handleSetVisitChart();
      });
    },
    async platformCompanyEarningsDateStatisticsData() {
      let params = {
        dateType: this.dateType,
        orgId: this.orgId,
      };
      let data = await platformCompanyEarningsDateStatistics(params);
      this.amountOption.xAxis[0].data = data.map((o) => o.dateStr);
      this.amountOption.series[0].data = data.map((o) => o.money);
      this.echartsOption = this.amountOption;
      this.isHide = true;
      this.$nextTick(() => {
        this.$refs.EchartsRef.handleSetVisitChart();
      });
    },
    tabsClick(item) {
      this.currentItem = item.id;
      this.switchFn();
    },
    switchFn() {
      this.isHide = false;
      switch (this.currentItem) {
        case 1:
          this.platformCompanyBusiCountDateStatisticsData();
          break;
        case 2:
          this.platformCompanyEarningsDateStatisticsData();
          break;
        default:
          break;
      }
    },
  },
  mounted() {
    this.platformCompanyBusiCountDateStatisticsData();
  },
};
</script>

<style lang="less" scoped>
.business-info-right {
  margin: 18px 0 0 0;
  width: 100%;
  height: 360px;
  background: #f2f2f2;
}

.tabs-list {
  display: flex;
  padding: 20px;
  .tabs-item {
    margin-right: 20px;
    position: relative;
    padding-bottom: 8px;
    cursor: pointer;
    &::before {
      position: absolute;
      content: "";
      display: inline-block;
      width: 30%;
      height: 3px;
      left: 50%;
      bottom: 0;
      transform: translateX(-50%);
    }
  }
  .tabs-item-current {
    color: #0052d9;
    &::before {
      background: #0052d9;
    }
  }
}
.loading-main {
  margin: 0 auto;
  padding-top: 150px;
  display: flex;
  justify-content: center;
}
</style>
